package com.woniu.postbar.controller;

import com.woniu.common.entity.PageData;
import com.woniu.common.entity.Result;

import com.woniu.postbar.entity.dto.PostCommentDTO;
import com.woniu.postbar.entity.vo.PostCommentVO;
import com.woniu.postbar.pojo.PostComment;
import com.woniu.postbar.service.IPostCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wu
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/postComment")
@Api(tags = "评论模块")
public class PostCommentController {

    @Autowired
    private IPostCommentService postCommentService;

    @PostMapping("/addPostComment")
    @ApiOperation("用户添加评论")
    public Result addPostComment(@RequestBody PostCommentDTO postCommentDTO){
        boolean addComment = postCommentService.addPostComment(postCommentDTO);
        return Result.ok(addComment);
    }


    @PostMapping("/search/{currentPage}/{pageSize}")
    @ApiOperation("分页查询")
    public Result<PageData<List<PostCommentVO>>> select(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody PostCommentDTO postCommentDTO
    ){
        PageData<List<PostCommentVO>> pageResult = postCommentService.search(currentPage,pageSize,postCommentDTO);
        return Result.ok(pageResult);
    }

    //    @GetMapping("/listComment")
//    @ApiOperation("查询所有评论")
//    public Result<List<PostCommentVO>> listComment(PostCommentDTO postCommentDTO){
//        List<PostCommentVO> postCommentVOS = postCommentService.listComment(postCommentDTO);
//        return Result.ok(postCommentVOS);
//    }
}
